package org.openfans.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.openfans.util.HtmlEncoder;

/**
 * 描述：软件设计为一种特殊的tag<br>
 * 日期：2006-5-29<br>
 * 
 * @author 张俊<br>
 * @email:pesome@gmail.com<br>
 */

public class RootTag extends Tag {
	private String icon;

	private String mainURL;

	private String intro;

	private Fans lastModifyFans;

	private Date lastModifyDate;

	private Set<UseStatus> useStatusSet;

	private Set<Fans> modifierSet;

	private Set<RootTagRemark> remarkSet;

	private Set<RootTagDigg> diggSet;

	private int remarkCount;

	private int diggCount;

	private List<Link> linkList;

	private boolean recommendated;

	public List<Link> getLinkList() {
		return linkList;
	}

	public void setLinkList(List<Link> linkList) {
		this.linkList = linkList;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public String getMainURL() {
		return mainURL;
	}

	public void setMainURL(String mainURL) {
		this.mainURL = mainURL;
	}

	public Set<UseStatus> getUseStatusSet() {
		return useStatusSet;
	}

	public void setUseStatusSet(Set<UseStatus> useStatusSet) {
		this.useStatusSet = useStatusSet;
	}

	public void addUseStatus(UseStatus useStatus) {
		if (useStatusSet == null) {
			useStatusSet = new HashSet<UseStatus>();
		}
		useStatusSet.add(useStatus);
	}

	public String getShortIntro() {
		if (intro.length() > 200) {
			return HtmlEncoder.encode(intro.substring(0, 200) + "......");
		} else {
			return HtmlEncoder.encode(intro);
		}
	}

	public String getHtmlIntro() {
		return HtmlEncoder.encode(intro);
	}

	public Date getLastModifyDate() {
		return lastModifyDate;
	}

	public void setLastModifyDate(Date lastModifyDate) {
		this.lastModifyDate = lastModifyDate;
	}

	public Fans getLastModifyFans() {
		return lastModifyFans;
	}

	public void setLastModifyFans(Fans lastModifyFans) {
		this.lastModifyFans = lastModifyFans;
	}

	public void addLink(Link l) {
		if (linkList == null) {
			linkList = new ArrayList<Link>();
		}
		linkList.add(l);
	}

	public void removeLink(Link l) {
		if (linkList != null) {
			linkList.remove(l);
		}
	}

	void fill() {
		this.setSubmitDate(new Date());
		// 自动给不加http://的补上
		String url = this.getMainURL();
		if (url.indexOf("http://") < 0) {
			this.setMainURL("http://" + url);
		}
		if ("".equals(this.getIcon())) {
			this.setIcon("images/defaultTag.gif");
		}
	}

	public boolean isRecommendated() {
		return recommendated;
	}

	public void setRecommendated(boolean recommendated) {
		this.recommendated = recommendated;
	}

	public Set<Fans> getModifierSet() {
		return modifierSet;
	}

	public void setModifierSet(Set<Fans> modifierSet) {
		this.modifierSet = modifierSet;
	}

	public Set<RootTagRemark> getRemarkSet() {
		return remarkSet;
	}

	public void setRemarkSet(Set<RootTagRemark> remarkSet) {
		this.remarkSet = remarkSet;
	}

	public void addRemark(RootTagRemark remark) {
		if (remarkSet == null) {
			remarkSet = new HashSet<RootTagRemark>();
		}
		remarkSet.add(remark);
		this.remarkCount++;
	}

	public void removeRemark(RootTagRemark remark) {
		remarkSet.remove(remark);
		this.remarkCount--;
	}

	public int getRemarkCount() {
		return remarkCount;
	}

	public void setRemarkCount(int remarkCount) {
		this.remarkCount = remarkCount;
	}

	public int getDiggCount() {
		return diggCount;
	}

	public void setDiggCount(int diggCount) {
		this.diggCount = diggCount;
	}

	public Set<RootTagDigg> getDiggSet() {
		return diggSet;
	}

	public void setDiggSet(Set<RootTagDigg> diggSet) {
		this.diggSet = diggSet;
	}

	public void addDigg(RootTagDigg digg) {
		if (diggSet == null) {
			diggSet = new HashSet<RootTagDigg>();
		}
		diggSet.add(digg);
		this.diggCount++;
	}

	public void removeDigg(RootTagDigg digg) {
		diggSet.remove(digg);
		this.diggCount--;
	}

}
